let data = [
    {
        name: "goods",
        children: [
            {
                name: "fruit",
                children: [
                    {
                        name: "apple",
                        children: [
                            {name: "red-apple"},
                            {name: "green-apple"}
                        ]
                    }
                ]
            }
        ]
    }
]

function calc(data,result) {
    if (result == null) {
        result = [];
    }
    for (const v of data) {
        if (v.name) {
            result.unshift(v.name.toUpperCase());
        } 
        if (v.children) {
            calc(v.children,result);
        }
    }
    return result;
}

console.log(calc(data));